package com.njwb.service.impl;

import com.njwb.dao.UserDao;
import com.njwb.dao.impl.UserDaoImpl;
import com.njwb.entity.User;
import com.njwb.exception.PhoneExistsException;
import com.njwb.service.UserService;

/**
 * Description: 类的描述
 * Author: yuandeyin@itany.com
 * Date: 2025-08-12 13:47
 * Version: 1.0
 */
public class UserServiceImpl implements UserService {
    //由于业务层中牵涉到数据库的操作
    //Service中持有一个相关DAO的对象引用
    private UserDao userDao = new UserDaoImpl();
    @Override
    public void regist(User user) {
        User userFromDB = userDao.findByPhone(user.getPhone());
        if(null == userFromDB){//手机号码没有被使用
            //保存用户
            userDao.insert(user);
        }else{//不可用使用
            throw new PhoneExistsException("手机号码已经存在，不可用");
        }
    }
}
